﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Entities;
using System.Data.OleDb;
using System.Data;
using System.Data.Common;

namespace DataAccess
{
    public partial class MySQLDataAccess : IDataAccess
    {
        private StringBuilder QueryStringBuilder;

        #region IDataAccess Members
        /// <summary>
        /// Gets the List of Tables from database defined in ConnectionInformation Object.
        /// </summary>
        /// <param name="connectionInformation"></param>
        /// <returns></returns>
        public List<string> GetTableList(ConnectionInformation connectionInformation)
        {
            QueryStringBuilder = new StringBuilder();
            QueryStringBuilder.Append("select Table_Name from INFORMATION_SCHEMA.TABLES where TABLE_SCHEMA='");
            QueryStringBuilder.Append(connectionInformation.DataBaseName);
            QueryStringBuilder.Append("' And Table_Type='BASE TABLE'");

            return GenerateTableList( ExecuteQuery(connectionInformation, QueryStringBuilder.ToString()) , 1,0);
        }
        /// <summary>
        /// Get Information of a Table and return TableInformation Object.
        /// But it will retrieve only sample data in dataTable(DataTable).
        /// For getting full data call GetFullData(ConnectionInformation connectionInformation, string tableName,out TableInforamation tableInformation) after calling this function.
        /// </summary>
        /// <param name="connectionInformation"></param>
        /// <param name="TableName"></param>
        /// <returns></returns>
        public TableInformation GetTableInformation(ConnectionInformation connectionInformation, string TableName)
        {
            TableInformation tableInformation = new TableInformation(); ;

            string QueryString = "Select * from " + TableName + " Limit 10";

            tableInformation.DataTable = ExecuteQuery(connectionInformation, QueryString);

            List<Column> Columnlist = GenerateColumnInformation(connectionInformation, TableName, QueryString);

            tableInformation.ColumnList = Columnlist;

            tableInformation.DataTable.TableName = TableName;

            return tableInformation;
        }

        

       
        #endregion
    }
}

